﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.IBLL;
using HZ.Supervise.Model;
using System.Data;

namespace HZ.Supervise.Web.Company
{
    public partial class CompanyPsList_JG_DZ : BasePage
    {
        HZ.Supervise.IBLL.IExecuteContext iEC = HZ.Supervise.BLLFactory.ExecuteContext();
        IBLL_User iu = BLLFactory.BLL_User();
        KeyOperationLogJG kj;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (CurrentAccount.GetUser().Org.Area.AreaID != Constants.CURRENT_DEPLOY_AREAID)
                {
                    ddlCity.SelectedValue = CurrentAccount.GetUser().Org.Area.AreaID;
                    ddlCity.Enabled = false;
                }
                //绑定基本信息
                BindMedhchilData(); 
                //绑定列表数据
                CompanyPsList_JG_DataBind();
            }
        }

        /// <summary>
        /// 绑定列表数据 
        /// </summary>
        private void CompanyPsList_JG_DataBind()
        {
            int t = 0;
            HZ.Supervise.Model.View.HospitalProcureCatalog hospro = new HZ.Supervise.Model.View.HospitalProcureCatalog();
            hospro.ProcureCatalogID = Request.QueryString["ProcureCatalogID"];
            hospro.CompanyName_PS = HZ.Supervise.DAL.DAL_Helper.Replace(txtCompanyPS.Text.ToString().Trim());
            if (!string.IsNullOrEmpty(ddlCity.SelectedValue))
            {
                //hospro.AreaID = AreaControl1.SelectedAreaID;
                hospro.AreaID = ddlCity.SelectedValue;
            }
            System.Data.DataTable dt = iEC.GetCompanyPsList_JG_DZ(hospro, this.AspNetPager_CompanyPsList_JG.CurrentPageIndex, AspNetPager_CompanyPsList_JG.PageSize, out t);
            AspNetPager_CompanyPsList_JG.RecordCount = t;
            gvwPSLInfo.PageSize = AspNetPager_CompanyPsList_JG.PageSize;
            this.gvwPSLInfo.DataSource = dt;
            this.gvwPSLInfo.DataBind();
            AddLog(string.Format("查询流水号[{0}]产品的有关配送企业信息!(低值产品信息列表)", Request["ProcureCatalogID"]));
        }

        /// <summary>
        /// 查询数据事件 
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager_CompanyPsList_JG.CurrentPageIndex = 1;
        }

        /// <summary>
        /// 分页事件 
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void CompanyPsList_JG_PageChanged(object sender, EventArgs e)
        {
            CompanyPsList_JG_DataBind();
        }

        /// <summary>
        /// 导出数据事件 
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void btnExcel_Click(object sender, EventArgs e)
        {
            int t = 0;
            HZ.Supervise.Model.View.HospitalProcureCatalog hospro = new HZ.Supervise.Model.View.HospitalProcureCatalog();
            hospro.ProcureCatalogID = Request.QueryString["ProcureCatalogID"];
            hospro.CompanyName_PS = HZ.Supervise.DAL.DAL_Helper.Replace(txtCompanyPS.Text.ToString().Trim());
            if (!string.IsNullOrEmpty(ddlCity.SelectedValue))
            {
                //hospro.AreaID = AreaControl1.SelectedAreaID;
                hospro.AreaID = ddlCity.SelectedValue;
            }
            System.Data.DataTable dt = iEC.GetCompanyPsList_JG_DZ(hospro, 0, 0, out t);
            if (dt.Rows.Count > 0)
            {
                AddLog(string.Format("导出流水号[{0}]产品的有关配送企业信息成功!(低值产品信息列表)", Request["ProcureCatalogID"]));
                ExportFile.Instance.ExportData(dt, gvwPSLInfo, this.Page);
            }
        }

        /// <summary>
        /// 返回上一页事件 
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void btnFinish_Click(object sender, EventArgs e)
        {
            HZ.Web.WebUtil.RedirectByScript("CompanyGoodsList_DZ.aspx");
        }


        /// <summary>
        /// 绑定基本数据 
        /// </summary>
        private void BindMedhchilData()
        {
            try
            {
                int t = 0;
                HZ.Supervise.Model.View.HospitalProcureCatalog hospro = new HZ.Supervise.Model.View.HospitalProcureCatalog();
                hospro.ProcureCatalogID = Request.QueryString["ProcureCatalogID"];
                DataTable dt = iEC.GetCompanyPsList_JG_Message_DZ(hospro, 0, 0, out t);
                if (dt.Rows.Count > 0)
                {
                    lblGoodsName.Text = dt.Rows[0]["GoodsName"].ToString();
                    lblProductname.Text = dt.Rows[0]["ProductName"].ToString();
                    lblRegName.Text = dt.Rows[0]["RegName"].ToString();
                    lblBrand.Text = dt.Rows[0]["Brand"].ToString();
                    lblUnit.Text = dt.Rows[0]["Unit"].ToString();
                    lblCompanyName_SC.Text = dt.Rows[0]["CompanyName_SC"].ToString();
                }
            }
            catch (Exception ex)
            { 
                return;
            }
        }
        /// <summary>
        /// 添加日志
        /// </summary>
        /// <param name="msg"></param>
        private void AddLog(string msg)
        {
            kj = new KeyOperationLogJG();
            kj.OperationLogSerialID = Guid.NewGuid().ToString();
            kj.Operator = CurrentAccount.GetUser().UserID;
            kj.OrgID = CurrentAccount.GetUser().Org.OrgID;
            kj.OperateTime = DateTime.Now;
            kj.OperateMessage = msg;
            iu.AddKeyOperationLog(kj);
        }
    }
}